﻿using RestSharp;
using System;
using Ymatou.ServiceCenter;
using Ymatou.User.Dto.Auth;
using YmtAuth.AppService;
using YmtAuth.Common.Extend;
using YmtAuth.Dto;
using YmtSystem.CrossCutting;
using ResetService = ServiceStack.Service;

namespace YmtAuth.Web.Handlerv2
{
    
    
    public class SignHandler : ResetService
    {
        private ITokenAppService TokenAppService { get { return LocalServiceLocator.GetService<ITokenAppService>(); } }

        //根据token 获取用户ID
        [ServiceRegister("/json/reply/SignAuthRequestDto", Method.GET)]
        public object Get(SignAuthRequestDto request)
        {
            YmtSystemAssert.AssertArgumentNotNull(request, "无效的SignAuthRequestDto");
            request.RequestId = Guid.NewGuid().ToString("N");

            using (var mm = Ymatou.PerfMonitorClient.MethodMonitor.New("auth_GetUserByToken"))
            {
                return Action_Extend.ActionWatch( () => TokenAppService.GetUserByToken(request), "[GetUserByTokenEnter]Rid:" + request.RequestId);
            }
     
        }
        //签名校验
        [ServiceRegister("/json/reply/SignAuthRequestDto", Method.POST)]
        public object Post(SignAuthRequestDto request)
        {
            YmtSystemAssert.AssertArgumentNotNull(request, "无效的SignAuthRequestDto");
            request.RequestId = Guid.NewGuid().ToString("N");

            using (var mm = Ymatou.PerfMonitorClient.MethodMonitor.New("auth_CheckSign"))
            {
                return Action_Extend.ActionWatch(() => TokenAppService.CheckSign(request), "[CheckSignEnter]Rid:"+request.RequestId);
            }
        }
    }
}